package dk.isten.andro.julesangbog;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class SupportActivity extends Activity 
{

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		WebView webView = new WebView(this);

		webView.loadUrl("file:///android_asset/support.html");
		
		//http://stackoverflow.com/questions/3197430/how-to-set-anchor-tag-mailto-attribute-in-webview-android
		webView.getSettings().setJavaScriptEnabled(true);
	    webView.setWebViewClient( new YourWebClient()); 

		setContentView(webView);
	}

	private class YourWebClient extends WebViewClient
	{     
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) 
		{
			if (url.contains("andro@isten.dk")) 
			{
				String email = "andro@isten.dk";
				sendEmail(email);
				return super.shouldOverrideUrlLoading(view, url);
			}
			view.loadUrl(url);
			return true;
		}

		private void sendEmail(String email) 
		{
			final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
			emailIntent.setType("plain/text");
			emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
	
			
			String mySubject = "Vedr.: Android App'en - Julesalmer";
			emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mySubject);
			String myBodyText = "Hej Martin \n\nJulesalmer fejler når...\n\nJeg synes..." +
					"\n\nHvordan...  \n\n\nMvh";
			emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, myBodyText);
			startActivity(Intent.createChooser(emailIntent, "Send e-mail..."));

		}
	}
}
